//我的资产页面内容（报错）原因：datasource必须获取为数组
import React, { useState, useEffect } from 'react';
import { Card, Space,Statistic,Cascader, InputNumber, Select,Button,Modal ,message,Table, Col, Row ,Pagination, Drawer,Slider,scroll} from 'antd';
import { SettingOutlined } from '@ant-design/icons';
import axios from 'axios';
import { Link, useRouter } from 'next/router';
import { PieChart} from 'recharts';
import MyChart from './pieChart';

const Info = () => {
  
  const [strategyInfo, setStrategyInfo] = useState([]);
  //交易记录表格
  const columns_strategy = [
    {
        title: '股票代码',
        dataIndex: 'stock_code',
        key: 'total_price',
      },
      {
        title: '自动交易',
        dataIndex: 'auto_trade',
        key: 'auto_trade',
        render: (text, record) => (
            <span>{text ? '✓' : '✗'}</span>
          ),
      },
      {
        title: '交易限额',
        dataIndex: 'limit_amount',
        key:'limit_amount',
      },
      {
        title: '动量策略',
        dataIndex: 'momentum_strategy',
        key:'momentum_strategy',
        render: (text, record) => (
            <span>{text ? '✓' : '✗'}</span>
          ),
      },
      {
        title: '均线策略',
        dataIndex: 'moving_average_strategy',
        key:'moving_average_strategy',
        render: (text, record) => (
            <span>{text ? '✓' : '✗'}</span>
          ),
      },
    {
      title: '布林带策略',
      dataIndex: 'bollinger_bands_strategy',
      key:'bollinger_bands_strategy',
      render: (text, record) => (
        <span>{text ? '✓' : '✗'}</span>
      ),
    },
    {
      title: '%75止损策略',
      dataIndex: 'stop_loss_strategy',
      key: 'stop_loss_strategy',
      render: (text, record) => (
        <span>{text ? '✓' : '✗'}</span>
      ),
    },
    {
      title: 'ATR止损策略',
      dataIndex: 'atr_stop_loss_strategy',
      key: 'atr_stop_loss_strategy',
      render: (text, record) => (
        <span>{text ? '✓' : '✗'}</span>
      ),
    },
    
  ];
  
  
  
  
  //获取交易记录
  useEffect(() => {
    const fetchTradeRecords = async () => {
      try {
        const token = localStorage.getItem('token');
        const response = await axios.get('/api/trade/strategy_info', {
          headers: {
            Authorization: `Bearer ${token}`
          }
        });
        console.log("获得的交易策略数据是:", response.data.data.data);
        setStrategyInfo(response.data.data.data);
      } catch (error) {
        console.log('Error:', error);
        // 登录失败时的处理
        if (error.response) {
          // 服务器返回了错误响应
          const errorMessage = error.response.data.msg || '信息获取失败';
          message.error(errorMessage);
        } else if (error.request) {
          // 请求已发出，但没有收到响应
          message.error('请求失败，请检查网络连接');
        } else {
          // 发送请求时出了问题
          message.error('请求失败，请检查后端服务是否可用');
        }
      }
    };
    fetchTradeRecords();
  }, []);

  

return (
    
      <Table columns={columns_strategy} dataSource={strategyInfo} scroll={{y:600}} pagination={ false}/>  
      
      
    
)
};
export default Info;